<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>04-单元素/组件的入场和出场 过渡和动画</title>
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
    />
    <style>
      @keyframes move {
        0% {
          transform: translateX(100px);
        }

        50% {
          transform: translateX(50px);
        }
        100% {
          transform: translateX(0);
        }
      }

      /*.v-enter-from{
          opacity: 0;
      }*/
      /*.hello{
        animation: move 2s ease-in;
      }

      .bye{
        animation: move 2s ease-in;
      }*/

      .v-enter-from {
        color: red;
      }

      .v-enter-active,
      .v-leave-active {
        /*transition: opacity 2s ease;*/
        animation: move 3s ease-in;
        transition: all 10s ease;
      }

      .v-leave-active {
        color: red;
      }

      /*.v-enter-to{
          opacity: 1;
      }*/

      /*.v-leave-to{
          opacity: 0;
      }*/
    </style>
  </head>
  <body>
    <script src="https://unpkg.com/vue@next"></script>
    <div id="root"></div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            show: false,
          };
        },

        methods: {



          handleClick() {
            this.show = !this.show;
          },


          handleBeforeEnter(el){
            el.style.color = "red";
          },

          handleEnterActive(el, done){
            const animation =  setInterval(() => {
                const color = el.style.color;

                if(color === "red"){
                    el.style.color = "green";
                }else{
                    el.style.color = "red";
                }
              },1000)

              setTimeout(() => {
                  clearInterval(animation);
                  done();
              }
              ,4000)
          },


          handleEnterEnd(){
            alert(666);
          }
        

          
        },

        //template: `
        //        <transition :duration="{enter:1000, leave:3000}">
        //           <div v-show="show">hello world</div>
        //        </transition> 
        //           <button @click="handleClick">切换</button>  
        //        `,
        template: `
                <transition
                    :css="false"
                    @before-enter="handleBeforeEnter"  
                    @enter="handleEnterActive"  
                    @after-enter="handleEnterEnd" 
                    @before-leave=""
                    @leave = ""
                    @after-leave =""
                    
                >
                   <div v-show="show">hello world</div>
                </transition> 
                   <button @click="handleClick">切换</button>  
                `,
      });

      const vm = app.mount("#root");
    </script>
  </body>
</html>
